package com.ysd.lis.controller.lab;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.bac.BacStainingResult;
import com.ysd.lis.entity.lab.LabMaininfo;
import com.ysd.lis.entity.lab.WlConfig;
import com.ysd.lis.entity.lab.WlConfigPatsetting;
import com.ysd.lis.request.wl.WlConfigParam;
import com.ysd.lis.service.SysRuleSetService;
import com.ysd.lis.service.lab.LabMaininfoService;
import com.ysd.lis.service.lab.WlConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 * 检验报告-信息配置 前端控制器
 * </p>
 *
 * @author WangHao
 * @since 2024-01-18
 */
@RestController
@RequestMapping("/lab/wlConfig")
public class WlConfigController extends BaseController {

    @Autowired
    private WlConfigService wlConfigService;
    @Autowired
    private SysRuleSetService sysRuleSetService;
    @Autowired
    private LabMaininfoService labMaininfoService;

    @ApiOperation("获取配置信息")
    @GetMapping("/findWlConfig")
    public Result findWlConfig(WlConfigParam wlConfigParam) {
        return wlConfigService.findWlConfig(wlConfigParam);
    }

    @ApiOperation("获取比例及列表高度配置信息")
    @GetMapping("/findWlConfigSizeAndHeight")
    public Result findWlConfigSizeAndHeight(WlConfigParam wlConfigParam) {
        return wlConfigService.findWlConfigSizeAndHeight(wlConfigParam);
    }

    @ApiOperation("通过报告单元获取病人配置信息")
    @GetMapping("/findWlConfigByRptGroup")
    public Result findWlConfigByRptGroup(WlConfigParam wlConfigParam) {
        return wlConfigService.findWlConfigByRptGroup(wlConfigParam);
    }

    @ApiOperation("新增或修改配置信息")
    @PostMapping("/insertOrUpdateConfigsting")
    public Result insertOrUpdateConfigsting(@RequestBody List<WlConfig> configs) {
        return wlConfigService.insertOrUpdateConfigsting(configs);
    }

    @ApiOperation("批量删除配置信息")
    @PostMapping("/batchDeleteConfigsting")
    public Result batchDeleteConfigsting(@RequestBody List<WlConfig> configs) {
        return wlConfigService.batchDeleteConfigsting(configs);
    }

    @ApiOperation("获取细菌条码号规则")
    @GetMapping("/getBacSampleNoByRule")
    public Result getBacSampleNoByRule(String sampleDa, String rptGroup) {

        LambdaQueryWrapper<LabMaininfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        Timestamp startTime = Timestamp.valueOf(sampleDa.substring(0, 10) + " 00:00:00");
        Timestamp endTime = Timestamp.valueOf(sampleDa.substring(0, 10) + " 23:59:59");
        lambdaQueryWrapper.ge(LabMaininfo::getSampleda, startTime);
        lambdaQueryWrapper.le(LabMaininfo::getSampleda, endTime);
        lambdaQueryWrapper.eq(LabMaininfo::getRptGroup, rptGroup);
        lambdaQueryWrapper.eq(LabMaininfo::getDelFlag, 0);

        int count = labMaininfoService.count(lambdaQueryWrapper);

        String a = sysRuleSetService.createRuleCodeListBySampleDa("BacSampleNo", 1, sampleDa, count);
        return Result.succ(1, "生成成功", a);
    }

}
